<?php

/**
 *  @FileComment            [类型属性公共模型]
 *  @ProjectName             项目名称：shopFrame
 *  @FileName                   文件名称：TypeAttrModel.class.php
 *  @Author                       yuerengui <596580041@qq.com>
 *  @Date                          2014-10-9 19:23:53
 *  *
 */
class TypeAttrModel extends Model {

        public $table = 'type_attr';
        public $validate = array(
            array('taname', 'nonull', '属性名不能为空', 2, 3),
            array('taname', 'maxlen:45', '属性名最大为45位', 2, 3),
            array('tavalue', 'nonull', '属性值不能为空', 2, 3)
        );
        public $auto = array(
            array('tavalue', '_tavalue', 'method', 2, 3)
        );

        public function _tavalue($value) {
                $value = explode('|', $value);
                $temp = array();
                foreach ($value as $v) {
                        if ($v) {
                                $temp[] = trim($v);
                        }
                }
                $temp = implode(',', $temp);
                return $temp;
        }

        public function add_data() {
                return $this->add();
        }

        public function get_data($tid = NULL) {
                return $this->where(array('type_tid' => $tid))->all();
        }

        public function get_class_data($tid = NULL, $class = NULL) {
                return $this->where(array('type_tid' => $tid, 'class' => $class))->all();
        }

        public function get_filed_data($tid, $field, $class) {
                return $this->where(array('type_tid' => $tid, 'class' => $class))->getField($field, 'true');
        }

        public function get_one_data($taid) {
                return $this->where(array('taid' => $taid))->find();
        }

        public function update_data($taid) {
                return $this->where(array('taid' => $taid))->update();
        }

        public function del_data($taid) {
                $this->where(array('taid' => $taid))->del();
        }

        public function get_taname_data($where) {
                return $this->where($where)->field('taname')->find();
        }

}
